% this a a wrapper to the mexfile mexMincut.cpp
% INPUT
%
% horizontalEdges: matrix of double weights M*(N-1) (M-rows, (N-1)-columns)
% 	containing symmetrical weight of each node to it's right neighbor. Note
% 	that this matrix is missing the rightmost column
%
% verticalEdges: matrix of double weights (M-1)*N ((M-1)-rows, N-columns)
% 	containing symmetrical weight of each node to it's bottom neighbor. Note
% 	that this matrix is missing the lowest row
%
% sourceWeights: matrix of double weights (M,N) connected to 
% 	the source 
% sinkWeights: matrix of double weights (M,N) connected to 
% 	the sink 
%
% OUTPUT
%
% segmentation: boolean matrix M*N (M-rows, N-columns) containing the
%	values 0 or 1 representing whether the  pixels is connected to the source
%	(0) or the sink (1)
%
% Author: Yair Movshovitz yairmov@cs
% based on findMincut.m by micham23	(January 2006)
function [segmentation] = minCut(horizontalEdges, verticalEdges, sourceWeights, sinkWeights)
% Check Syntax
	if (nargin ~= 4)
		error('Syntax: minCut(horizontalEdges, verticalEdges, sourceWeights, sinkWeights)');
	elseif (~strcmp(class(horizontalEdges), 'double') || ~strcmp(class(verticalEdges), 'double'))
		error('horizontalEdges and verticalEdges must be of type double!');
	elseif (~strcmp(class(sourceWeights), 'double') || ~strcmp(class(sinkWeights), 'double'))
		error('sourceWeights and sinkWeights must be of type double!');
	elseif ((size(verticalEdges, 1) + 1) ~= size(horizontalEdges, 1))
		error('verticalEdges and horizontalEdges matrix size mismatch!');
	elseif ((size(horizontalEdges, 2) + 1) ~= size(verticalEdges, 2))
		error('verticalEdges and horizontalEdges matrix size mismatch!');
    elseif (any((size(sourceWeights) ~= size(sinkWeights))))
		error('sourceWeights and sinkWeights matrix size mismatch!');
% more error checking should maybe be done here
	end

	% Call MEX function to do actual work
	segmentation = mexMincut(...
        true, horizontalEdges, verticalEdges, sourceWeights, sinkWeights);
